/**
 *博尔信基础开发平台
 *<br> 版权声明：厦门博尔信软件有限公司版权所有,违者必究
 *<br> Copyright:  Copyright (c) 2012
 *<br> Company:pearlsoft
 *<br> @author 蒋勇华
 *<br> 2012-4-12
 *<br> @version 1.0
 *————————————————————————————————————
 *修改记录
 *    修改者：叶华辉
 *    修改时间：
 *    修改原因：
 *——————————————————————————————————————
 */
package com.pearlsoft.webapp.sysmgr.menu;

import org.apache.commons.lang.StringUtils;

import com.pearlsoft.webapp.core.annotation.DataSetHandlerComponent;
import com.pearlsoft.webapp.core.dataset.DataSet;
import com.pearlsoft.webapp.core.dataset.Record;
import com.pearlsoft.webapp.core.dataset.Result;
import com.pearlsoft.webapp.core.web.basehandler.AbsDataSetHandler;
import com.pearlsoft.webapp.sysmgr.menu.service.MenuService;

/**
 *描述： 
 *
 *  
 */
@DataSetHandlerComponent(name = "MenuDataSetHandler")
public class MenuDataSetHandler extends AbsDataSetHandler{

	public void handler(DataSet ds, Result result) throws Exception {
		String menuId=	ds.getValue("menuID").toString();
		System.out.println(menuId);
	}

	public void menuUp(DataSet ds, Result result) throws Exception {
		String menuId=	ds.getValue("menuID").toString();
		MenuService menuService = this.getBean("menuService", MenuService.class);
		menuService.menuUp(menuId);
	}
	
	public void menuDown(DataSet ds, Result result) throws Exception {
		String menuId=	ds.getValue("menuID").toString();
		MenuService menuService = this.getBean("menuService", MenuService.class);
		menuService.menuDown(menuId);
	}	
	
	public void save(final DataSet ds, Result result) throws Exception {
		Record record = ds.getCurrentRecord();
		MenuService menuService = this.getBean("menuService", MenuService.class);
		menuService.save(record);
		result.getRecords().add(record);
	}
	
	
	@Override
	public void deleteAll(DataSet ds, Result result) throws Exception {
		MenuService menuService = this.getBean("menuService", MenuService.class);
		String objIds = (String) ds.getConditions().get("objIds");
		String[] ids = objIds.split(",");
		for(String id:ids){
			if( !StringUtils.isBlank(id)){
				menuService.deleteById(id);
			}
		}
	}
	
	public void delete(final DataSet ds, Result result) throws Exception {
		MenuService menuService = this.getBean("menuService", MenuService.class);
		String objId = (String) ds.getConditions().get("objId");
		menuService.deleteById(objId);
	}
	

}
